﻿using System;
using System.Data.SqlServerCe;

namespace eWallet.Data.Local.eWalletDataSetTableAdapters
{
	public partial class BlobsTableAdapter
	{
		/// <summary>
		/// Creates a new instance of the table adapter and specifies the full file
		/// path to the SQL Server Compact Edition database to connect to.
		/// </summary>
		/// <param name="dbPath">The full file path to the database file.</param>
		public BlobsTableAdapter(string dbPath)
		{
			this._connection = new SqlCeConnection(string.Format("Data Source={0}", dbPath));
		}

		public int Fill(eWalletDataSet.BlobsDataTable table, Guid blobId)
		{
			using (var cmd = this.CreateSelectCommand(blobId))
			{
				cmd.Connection = this.Connection;
				using (SqlCeDataAdapter adr = new SqlCeDataAdapter(cmd))
				{
					return adr.Fill(table);
				}
			}
		}

		protected SqlCeCommand CreateSelectCommand(Guid blobId)
		{
			SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM [Blobs] WHERE [Id] = @Id");
			cmd.Parameters.AddWithValue("@Id", blobId);

			return cmd;
		}
	}
}
